<?


JCAT_Package::ImportClass( ROOT_PATH.'Classes/Coder/class.CoderDocBase.php') ;

class ViewGtkDoc extends ViewDoc 
{
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$sPath=''	string	What's this Parameter ?
	 * @return	array
	 */
	public function ViewGtkDoc($sPath='')
	{
		$this->ViewDoc( __CLASS__, $sPath ) ;
	}

	/**
	 * what's this
	 * 
	 * @access	public
	 * @static 
	 * @return	string
	 */
	public function GetObjectClass()
	{
		return $this->Get('ViewClassName') ;
	}
	
	static public function GetControllerClassName()
	{
		return 'ViewGtk' ;
	}


	/**
	 * What's this Method ?
	 * 
	 * @access	protected
	 * @return	void
	 */
	protected function CreateNewDocument()
	{
		// 创建 新的文件 内容 :::::::::::::::::::
		$aTemplate = new JCAT_UIHtml() ;
		$aTemplate->SetVar('TheDoc',$this) ;
		
		// 模版文件
		$sTemplateFile = dirname(__FILE__).'/template.ViewGtk.php' ;
	
		// 产生内容
		$sNewSource = $aTemplate->Display( $sTemplateFile,false) ;
		
		// 调用 父类 创建一个空文件
		parent::CreateNewDocument() ;
		
		// 写入新文件
		file_put_contents($this->GetPath(),$sNewSource) ;
	}
	

	public function CreateCode_CallParentConstruct()
	{
		$sParentClass = $this->GetObjectClass() ;
		$sViewName = $this->Get('ViewName') ;
		$sWidgetId = $this->Get('MainWidgetID') ;
		$sGladeFile = $this->Get('UITemplatePath') ;
		if( $this->Get('InTemplateDir') )
		{
			$sGladeFile = basename($sGladeFile) ;
		}
		else
		{
			$sGladeFile = JCAT_FSO::GetRelativePath($this->GetPath(),$sGladeFile) ;
		}

		return "		\$this->{$sParentClass}('{$sViewName}','{$sGladeFile}','{$sWidgetId}',\$aParent) ;" ;
	}
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	string
	 */
	public function CreateCode_ForControllerMainRun()
	{
		$sTab = str_repeat("\t",2) ;
		$arrCodeLines = array() ;
		
		$sName = $this->Get('ViewName') ;
		
		$arrCodeLines[] = "{$sTab}// " . JCAT_Language::Sentence('显示视图 %s',$sName) ;
		$arrCodeLines[] = "{$sTab}\$aView = \$this->GetView('{$sName}') ;" ;
		$arrCodeLines[] = "{$sTab}JCAT_ASSERT::ASSERT_INSTANCE(\$aView,'JCAT_IView',JCAT_Language::Sentence('名为 %s 的视图未定义','{$sName}')) ;" ;
		
		if( $this->Get('ViewClassName')=='JCAT_GtkDialog' )
		{
			$arrCodeLines[] = "{$sTab}\$nResponse = \$aView->DoDialog() ;" ;
			$arrCodeLines[] = "{$sTab}if( \$nResponse===Gtk::RESPONSE_OK )" ;
			$arrCodeLines[] = "{$sTab}{" ;
			$arrCodeLines[] = "{$sTab}	// TODO ... ..." ;
			$arrCodeLines[] = "{$sTab}}" ;
			$arrCodeLines[] = "{$sTab}else" ;
			$arrCodeLines[] = "{$sTab}{" ;
			$arrCodeLines[] = "{$sTab}	// TODO ... ..." ;
			$arrCodeLines[] = "{$sTab}}" ;
			$arrCodeLines[] = '' ;
		}
		
		else 
		{
			$arrCodeLines[] = "{$sTab}\$aView->ShowView() ;" ;
		}
		
		return implode("\r\n",$arrCodeLines) ;
	}
}
?>